import Observer from './observer.js'
import Compiler from './compiler.js'

function MyVue(option) {
  this.$el = option.el
  this.$data = option.data
  this.$methods = option.methods
  new Observer(this.$data)
  new Compiler(this.$el,this)
  this.dataMountedToThis()
}
// 将data的属性挂载到this上
MyVue.prototype.dataMountedToThis = function () {
  const vm = this
  Object.keys(this.$data).forEach(key => {
    Object.defineProperty(vm, key, {
      get() {
        return vm.$data[key]
      },
      set(newVal) {
        if (vm.$data[key] != newVal) {
          vm.$data[key] = newVal
        }
      }
    })
  })
}


export default MyVue